const {dialog} = require("electron");
const {store} = require("./store");

//存放操作步骤及内容
const handleMap = new Map

const addInput = (win) =>{
    win.webContents.executeJavaScript(`
            var obj
            try{
                obj = {key:curr,value:document.evaluate(curr,document,null, XPathResult.ANY_TYPE, null).iterateNext().value}
            }catch (e) {
                var curr = '${store.get('curr')}'
                obj = {key:curr,value:document.evaluate(curr,document,null, XPathResult.ANY_TYPE, null).iterateNext().value}
            }
            obj
         `).then((obj)=>{
             if (obj.value === ''){
                 obj.value = "密码"
             }
        handleMap.set(obj.key,obj.value)
    }).catch((r)=>{
        dialog.showErrorBox("发生错误","该步骤获取异常请重试")
    })
}

const addClick = (win)=> {
    win.webContents.executeJavaScript(`
            var obj
            try{
                obj = {key:curr,value:'click'}
            }catch (e) {
                var curr = '${store.get('curr')}'
                obj = {key:curr,value:'click'}
            }     
            obj
         `).then((obj)=>{
        handleMap.set(obj.key,obj.value)
    })
}
const addQuery = (win)=>{
    win.webContents.executeJavaScript(`
            var obj
            try{
                obj = {key:curr,value:'query'}
            }catch (e) {
                var curr = '${store.get('curr')}'
                obj = {key:curr,value:'query'}
            }     
            obj
         `).then((obj)=> {
        handleMap.set(obj.key, obj.value)
    })
}
module.exports = {
    handleMap,
    addInput,
    addClick,
    addQuery
}
